package net.xinqushi.gc;

import java.io.*;

public class FileInputStreamGC {

    private final static String  TSET_FILE_NAME = "D:\\test\\test.txt";
    public static void main(String[] args) {
        try {
            TestInputStream fis = new TestInputStream(TSET_FILE_NAME);
            //fis.close();
            fis = null;
            while(true){
                System.gc();
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("gc");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    static class TestInputStream extends FileInputStream {

        public TestInputStream(String name) throws FileNotFoundException {
            super(name != null ? new File(name) : null);
        }

        @Override
        protected void finalize() throws IOException {
            super.finalize();
            System.out.println(this.getClass() + " is finalized");
        }
    }
}
